import java.util.Arrays;

public class BS
{
    public static void main(String[] args)
    {
        int[] arr = new int[]{1,0,2,4,5,9,6,10};
        System.out.println(Arrays.toString(bubbleSort(arr)));
        System.out.println(binarySearch(arr, 10));
        System.out.println(binarySearch(arr, 101));
    }

    public static int[] bubbleSort(int[] array)//bubble sort
    {
        int len = array.length;
        if(len<=1)
            return array;
        for(int i=0;i<len-1;i++)
        {
            for(int j=0;j<len-i-1;j++)
            {
                if(array[j]>array[j+1])
                {
                    int temp = array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;
                }
            }
        }
        return array;
    }


    public static int  binarySearch(int[] nums, int key)
    {
        int len = nums.length;
        if(len==0) return -1;
        if(len==1)  return nums[0]==key ? 0:-1;
        int left = 0;
        int right = len-1;
        while(left <= right)
        {
            int mid = left+((right-left)>>1);
            if(nums[mid] == key)
                return mid;
            if(nums[mid] < key) left = mid+1;
            else right = mid-1;
        }
        return -1;
    }
}
